package com.tansuo365.test1.controller.othercontrol;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tansuo365.test1.bean.otherbean.DProject;
import com.tansuo365.test1.service.otherservice.DProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/dproject")
public class DProjectController {

    @Autowired
    private DProjectService dProjectService;

    @RequestMapping("/getSelective")
    public Map<String,Object> getDProj(DProject dProject,@RequestParam(value="page",required=true)Integer page, @RequestParam(value="rows",required=true)Integer rows){
        Map<String, Object> resultMap = new HashMap<>();
        PageHelper.startPage(page, rows);
        List<DProject> selectiveByPage = dProjectService.findSelectiveByPage(dProject);
        PageInfo<DProject> pageInfo = new PageInfo<DProject>(selectiveByPage);
        resultMap.put("rows", pageInfo.getList());
        resultMap.put("total", pageInfo.getTotal());
        return resultMap;
    }

    @RequestMapping("/save")
    public Map<String, Object> save(DProject dProject) {
        Map<String, Object> resultMap = new HashMap<>();
        int code = dProjectService.insertSelective(dProject);
        if (code > 0) {
            resultMap.put("success", true);
        } else {
            resultMap.put("success", false);
        }
        return resultMap;
    }

    @RequestMapping("/update")
    public Map<String, Object> update(DProject dProject) {
        Map<String, Object> resultMap = new HashMap<>();
        int code = dProjectService.updateByPrimaryKeySelective(dProject);
        if (code > 0) {
            resultMap.put("success", true);
        } else {
            resultMap.put("success", false);
        }
        return resultMap;
    }

    @RequestMapping("/delete")
    public Map<String, Object> delete(@RequestParam("ids[]") Integer[] ids) {
        Map<String, Object> resultMap = new HashMap<>();
        int code = dProjectService.deleteBatchByPKArr(ids);
        if (code > 0) {
            resultMap.put("success", true);
        } else {
            resultMap.put("success", false);
        }
        return resultMap;
    }

}
